<?php
class Powerdelegation extends AppModel {
	var $name = 'Powerdelegation';
	var $displayField = 'workflow_id';
	//The Associations below have been created with all possible keys, those that are not needed can be removed
        var $virtualFields=array(
            'listTitle'=>'CONCAT("From ",Powerdelegation.amount_from, " to ",Powerdelegation.amount_to," - level : ",Powerdelegation.level_nb," - Procurement Validator : ")',
            'display'=>'CONCAT("From ",Powerdelegation.amount_from, " to ",Powerdelegation.amount_to," - level : ",Powerdelegation.level_nb," - Procurement Validator : ")',
         );
	var $belongsTo = array(
		'Workflow' => array(
			'className' => 'Workflow',
			'foreignKey' => 'workflow_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
        var $hasAndBelongsToMany = array(

                'User' => array(
			'className' => 'User',
			'joinTable' => 'powerdelegations_users',
			'foreignKey' => 'powerdelegation_id',
			'associationForeignKey' => 'user_id',
			'unique' => true,
		)
	);

        function getPowerdelegationByWorkflow($WkId=null){
            if (empty($WkId)){
                return false;
            }else{
                return $this->find('all',array(
                    'recursive'=>-1,
                    'conditions'=>array(
                       'workflow_id'=>$WkId
                    )
                ));
            }
        }
}
?>